package com.demo;

import java.util.*;

public class T4 {
    public static void main(String[] args) {
        //随机生成大于等于1000 小于10000的随机数
        int[] arr = randomNum(20,1000,10000);
        System.out.println(Arrays.toString(arr));

        int[] arr2 = {1205,2056,5056,3205,4623};
        //对数据元素每一个数的后3位进行升序（从小到大）排序，
        // 如果后3位相等，则按照原先的数字降序（由大到小）排序
        sortArr(arr2);
        System.out.println(Arrays.toString(arr2));
    }

    public static int[] randomNum(int length,int min,int max){
        int[] ints = new int[length];
        Random random = new Random();
        for (int i = 0; i < ints.length; i++) {
            ints[i] = random.nextInt(max - min) + min;
        }
        return ints;
    }

    public static int[] sortArr(int[] arr){
        Integer[] integers = new Integer[arr.length];
        for (int i = 0; i < arr.length; i++)
            integers[i] = (Integer) arr[i];

        Arrays.sort(integers,((o1, o2) -> {
            int a = o1 % 1000;
            int b = o2 % 1000;
            if (a == b)
                return o1 > o2? -1 : 1;
            return a - b ;
        }));

        for (int i = 0; i < arr.length; i++)
            arr[i] = integers[i];
        return arr;
    }
}